
// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { AboutSlint, Button } from "std-widgets.slint";
export component TestCase inherits Window {
    width: 700px;
    height: 700px;

    forward-focus: fs;

    in-out property <string> result;
    Text {text: result;}

    ContextMenuArea {
        Menu {
            MenuItem {
                title: "Entry1";
                activated => { debug("Entry1"); result += "Entry1"; }
            }
            Menu {
                title: "Entry2";
                MenuItem {
                    title: "New";
                    activated => { debug("New"); result += "New"; }
                }
                Menu {
                    title: "Open";
                    MenuItem {
                        title: "Open 1";
                        activated => { debug("1"); result += "Open1"; }
                    }
                    MenuSeparator {}
                    MenuSeparator {}
                    MenuItem {
                        title: "Open 2";
                        activated => { debug("2"); result += "Open2"; }
                    }
                    MenuSeparator {}
                }
            }
        }

        // When this focus scope has the focus, the ContextMenu can handle the Menu key
        fs := FocusScope {}
    }


    out property <bool> test: true;
}

/*
```rust
use slint::{platform::WindowEvent, platform::PointerEventButton, platform::Key, LogicalPosition, SharedString};

let instance = TestCase::new().unwrap();
assert!(instance.get_test());

// right click to open the menu
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(15.0, 15.0), button: PointerEventButton::Right });
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(15.0, 15.0), button: PointerEventButton::Right });
// press on entry1
instance.window().dispatch_event(WindowEvent::PointerPressed { position: LogicalPosition::new(25.0, 25.0), button: PointerEventButton::Left });
instance.window().dispatch_event(WindowEvent::PointerReleased { position: LogicalPosition::new(25.0, 25.0), button: PointerEventButton::Left });
assert_eq!(instance.get_result(), "Entry1");

// use the keyboard
instance.set_result("".into());
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::Menu));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::RightArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::Return));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::Return));
assert_eq!(instance.get_result(), "Open2");
```

```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
assert(instance.get_test());

// right click to open the menu
instance.window().dispatch_pointer_press_event(slint::LogicalPosition({15.0, 15.0}), slint::PointerEventButton::Right);
instance.window().dispatch_pointer_release_event(slint::LogicalPosition({15.0, 15.0}), slint::PointerEventButton::Right);
// press on entry1
instance.window().dispatch_pointer_press_event(slint::LogicalPosition({25.0, 25.0}), slint::PointerEventButton::Left);
instance.window().dispatch_pointer_release_event(slint::LogicalPosition({25.0, 25.0}), slint::PointerEventButton::Left);
assert_eq(instance.get_result(), "Entry1");

// use the keyboard
instance.set_result("");
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::Menu);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::RightArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::DownArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::Return);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::UpArrow);
slint_testing::send_keyboard_string_sequence(&instance, slint::platform::key_codes::Return);
assert_eq(instance.get_result(), "Open2");

```
*/
